<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<script>
		// 第一
		/*cnt = (function () {
			var num = 0;
			return function () {
				return ++num;
			}
		})();
		alert(cnt());		//1
		alert(cnt());		//2
		alert(cnt());		//3
		*/

		// 第二
		function t() {
			var num = 0;
			return function () {
				return ++num;
			}
		};
		cnt = t();
		alert(cnt());		//1
		alert(cnt());		//2
		alert(cnt());		//3
	</script>
</body>
</html>